package bobaini.com.fanout_exchange;

import bobaini.com.util.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.util.Scanner;

/**
 * ClassName: Product
 * author: bob.ly
 * Version: 1.0.0
 * DateTime: 2021/07/25-20:47:00
 * Description:
 * 生产者方:主要是发送消息到交换机中
 */
public class Product {
    private static final String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        /**
         * 声明交换机,同时指定交换机类型
         */
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入生产者信息");
        while (sc.hasNext()) {
            String message = sc.nextLine();
            channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
            System.out.println("生产者发送消息:" + message);
        }
    }
}
